package com.blue.blog.api.controller;

import com.blue.blog.api.pojo.Result;
import com.blue.blog.api.pojo.Tag;
import com.blue.blog.api.service.TagService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
public class TagController {
    @Autowired
    private TagService service;

    @GetMapping("/tags")
    public Result findAllTag() {
        List<Tag> tags = service.findAllTag();

        return Result.ok("查询成功", tags);
    }

    @PostMapping("/tag")
    public Result saveTag(@RequestBody Tag tag) {
        Integer result = service.saveTag(tag);

        return Result.ok("添加成功!", result);
    }

    @PutMapping("/tag")
    public Result updateTag(@RequestBody Tag tag) {
        Integer result = service.updateTag(tag);

        return Result.ok("更新成功!", result);
    }

    @DeleteMapping("/tag")
    public Result deleteTagById(@RequestParam Long id) {
        Integer result = service.deleteTagById(id);

        return Result.ok("删除成功!", result);
    }
}
